// ContextMenu.h

#ifndef __CONTEXT_MENU_H
#define __CONTEXT_MENU_H


#include "Common/MyFixes.h"
#include <vector>

class ATL_NO_VTABLE CZipContextMenu:
  public IContextMenu,
  public IShellExtInit,
  public CComObjectRootEx<CComMultiThreadModelNoCS>
{
public:

  enum class CommandInternalID
  {
    kCommandNULL,
    kOpen,
    kExtract,
    kExtractHere,
    kExtractTo,
    kTest,
    kCompress,
    kCompressEmail,
    kCompressTo7z,
    kCompressTo7zEmail,
    kCompressToZip,
    kCompressToZipEmail
  };
  
  
  BEGIN_COM_MAP(CZipContextMenu)
	  COM_INTERFACE_ENTRY(IContextMenu)
	  COM_INTERFACE_ENTRY(IShellExtInit)
  END_COM_MAP()



  DECLARE_PROTECT_FINAL_CONSTRUCT()

  HRESULT FinalConstruct();
  
  void FinalRelease();
  

  // IShellExtInit
  STDMETHOD(Initialize)(LPCITEMIDLIST pidlFolder, LPDATAOBJECT dataObject, HKEY hkeyProgID);

  // IContextMenu
  STDMETHOD(QueryContextMenu)(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags);
  STDMETHOD(InvokeCommand)(LPCMINVOKECOMMANDINFO lpici);
  STDMETHOD(GetCommandString)(UINT_PTR idCmd, UINT uType, UINT *pwReserved, LPSTR pszName, UINT cchMax);

  HRESULT InitContextMenu(const wchar_t *folder, const wchar_t **names, UINT32 numFiles);

 
private:

  struct CCommandMapItem
  {
    CommandInternalID	CommandInternalID;
    CString				Verb;
    CString				HelpString;
    CString				Folder;
    CString				ArcName;
    CString				ArcType;
	CCommandMapItem() {}
	CCommandMapItem(const CCommandMapItem & obj):
		CommandInternalID(obj.CommandInternalID),
		Verb(obj.Verb),
		HelpString(obj.HelpString),
		Folder(obj.Folder),
		ArcName(obj.ArcName),
		ArcType(obj.ArcType)
	{
	}
	CCommandMapItem & operator= (const CCommandMapItem & obj)
	{
		CommandInternalID = obj.CommandInternalID;
		Verb = obj.Verb;
		HelpString = obj.HelpString;
		Folder = obj.Folder;
		ArcName = obj.ArcName;
		ArcType = obj.ArcType;
		return *this;
	}
  };

  CStringVector _fileNames;
  bool _dropMode;
  CString _dropPath;
  typedef std::vector<CCommandMapItem> CommandsVector;
  CommandsVector  _commandMap;

  HRESULT GetFileNames(LPDATAOBJECT dataObject, CStringVector &fileNames);
  int FindVerb(const CString &verb);
  void FillCommand(CommandInternalID id, CString &mainString, CCommandMapItem &commandMapItem);
};

#endif
